//
//  HZWeatherViewModel.m
//  MyDoctor
//
//  Created by admin on 16/5/5.
//  Copyright © 2016年 heiyan. All rights reserved.
//

#import "HZWeatherViewModel.h"

@implementation HZWeatherViewModel

+(void)loadData:(void (^)(HZWeatherModel *, HZWeatherSingleDayModel *,NSString *date))resultBlock{
    
        
        //城市名称
        NSString *city = @"上海";
        
        //url地址
        NSString *urlString = @"http://api.map.baidu.com/telematics/v3/weather";
        
        //请求参数
        NSDictionary *params = @{@"location":city,@"output":@"json",@"ak":@"17IvzuqmKrK1cGwNL6VQebF9"};
        
        [[HZNetTools sharedTools] getRequest:urlString parameters:params finishedBlock:^(id responstObject, NSError *error) {
            if (error != nil) {
                NSLog(@"%@",error);
            }
            
            //        NSLog(@"%@",responstObject);
            
            //结果字典
            NSDictionary *resultsDict = responstObject[@"results"][0];
            
            //字典转模型
            HZWeatherModel *weatherModel = [HZWeatherModel weatherModelWithDict:resultsDict];
   
            //天气的数组
            NSArray *dataArray = weatherModel.weather_data;
            
            
            HZWeatherSingleDayModel *model = [HZWeatherSingleDayModel weatherModelWithDict:dataArray[0]];
            
            NSString *date = responstObject[@"date"];
            
            resultBlock(weatherModel,model,date);
            
        }];
        
        
    
}

@end
